import 'package:BeeApp/MainPage/MainModelPage.dart';
import 'package:BeeApp/MainPage/MainOrderModel.dart';
import 'package:BeeApp/MainPage/MainToolPage.dart';
import 'package:BeeApp/MainPage/http_request.dart';
import 'package:amap_map_fluttify/amap_map_fluttify.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:tobias/tobias.dart' as tobias;
import 'package:fluwx/fluwx.dart' as fluwx;
import 'package:url_launcher/url_launcher.dart';

class UserOrderNewsPage extends StatefulWidget {
  final String orderID;
  UserOrderNewsPage(this.orderID, {Key key}) : super(key: key);

  @override
  _UserOrderNewsPageState createState() => _UserOrderNewsPageState();
}

class _UserOrderNewsPageState extends State<UserOrderNewsPage> {
  AmapController _controller;
  LatLng center01 = LatLng(39.90960, 116.397228);
  LatLng center02 = LatLng(39.90960, 116.497228);

  final otherText01 = TextEditingController();
  bool isShow = false;
  MainOrderNewsModel orderNewsModel;
  // 订单状态 1 待接单 2 待取件 3 待送达 4 已完成 5 已取消订单 6 已放弃 7 已评价
  int orderType;
  int remove = 0;
  String removeStr = "";
  List<LatLng> polylineArr = [];

  CarUserNews carUserNews;
  DisOrderModel disOrderModel;

  @override
  void initState() {
    super.initState();
    uploadData();
    fluwx.weChatResponseEventHandler.listen((res) {
      if (res is fluwx.WeChatPaymentResponse) {
        print("支付结果" + res.type.toString());
        uploadData();
      }
    });
  }

  void uploadData() {
    DioUtils.postHttp(
      context,
      "Usercommon/order_detail",
      parameters: {
        "token": getData("token"),
        "order_id": widget.orderID,
      },
      onSuccess: (t) {
        print(t);
        MainModel model = MainModel.fromJson(t);
        if (model.code == 1 && model.data != null) {
          if (mounted) {
            setState(() {
              orderNewsModel = MainOrderNewsModel.fromJson(t);
              orderType = orderNewsModel.data.orderStatus;
              center01 = LatLng(
                double.parse(orderNewsModel.data.sLat.toString()),
                double.parse(orderNewsModel.data.sLng.toString()),
              );
              center02 = LatLng(
                double.parse(orderNewsModel.data.rLat.toString()),
                double.parse(orderNewsModel.data.rLng.toString()),
              );
              print("订单类型" + orderNewsModel.data.orderStatus.toString());
              print("支付类型" + orderNewsModel.data.payStatus.toString());
              addMarker();
            });
          }
        } else {
          showToast(model.msg);
        }
      },
      onError: (error) {
        print(error);
      },
    );
  }

  //显示发货 收货位置
  void addMarker() async {
    await _controller?.addMarkers([
      MarkerOption(
        coordinate: center01,
        infoWindowEnabled: false,
        anchorV: 1,
        iconProvider: AssetImage('images/MapFaImage.png'),
      ),
      MarkerOption(
        title: "biaotia",
        snippet: "fubiao",
        coordinate: center02,
        anchorV: 1,
        infoWindowEnabled: true,
        iconProvider: AssetImage('images/MapShouImage.png'),
      ),
    ]);
    await _controller?.addDriveRoute(
        from: center01, to: center02, lineWidth: 20);
    await _controller?.zoomToSpan([center01, center02]);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar(context, "订单详情"),
      body: Stack(children: [
        // AmapView(
        //   zoomLevel: 16,
        //   rotateGestureEnabled: false,
        //   onMapCreated: (controller) async {
        //     _controller = controller;
        //     await AmapLocation.instance
        //         .init(iosKey: 'e5b94ea20faba1746723d30ad211574d');
        //     addMarker();
        //     // await _controller?.addDriveRoute(
        //     //     from: center01, to: center02, lineWidth: 20);
        //     // await _controller?.zoomToSpan([center01, center02]);
        //   },
        // ),
        // remove == 0 ? orderView() : removeView(),
        Positioned(
            child: Column(children: [
          Expanded(
            child: AmapView(
              zoomLevel: 16,
              rotateGestureEnabled: false,
              onMapCreated: (controller) async {
                _controller = controller;
                await AmapLocation.instance
                    .init(iosKey: 'e5b94ea20faba1746723d30ad211574d');
                addMarker();
              },
            ),
          ),
          orderNewsView()
        ])),
        remove == 0 ? Container() : removeView(),
      ]),
    );
  }

  Widget orderNewsView() {
    return orderNewsModel == null
        ? Container()
        : Container(
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(6), topRight: Radius.circular(6)),
              boxShadow: [
                BoxShadow(
                    color: Colors.black12,
                    offset: Offset(0.0, -1.0), //阴影xy轴偏移量
                    blurRadius: 15.0, //阴影模糊程度
                    spreadRadius: 1.0 //阴影扩散程度
                    )
              ],
            ),
            child: Column(
              children: <Widget>[
                Container(
                  padding: EdgeInsets.only(
                    left: setWidth(30),
                    right: setWidth(30),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Text(
                        "订单详情",
                        style: TextStyle(
                          color: Color(0xFF333333),
                          fontSize: setFontSize(32),
                        ),
                      ),
                      IconButton(
                        icon: Image.asset(
                          !isShow
                              ? "images/OrderShowImage.png"
                              : "images/OrderHideImage.png",
                          width: setWidth(130),
                        ),
                        onPressed: () async {
                          print("object");
                          setState(() {
                            isShow = !isShow;
                          });
                          await _controller?.zoomToSpan([center01, center02]);
                        },
                      ),
                      Text(
                        "订单详情",
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: setFontSize(32),
                        ),
                      ),
                    ],
                  ),
                ),
                // 判断车主信息 是否展示
                orderType == 1 || orderType == 5
                    ? Container()
                    : Container(
                        padding: EdgeInsets.all(setWidth(18)),
                        child: Container(
                          color: Color(0xFFF2F2F2),
                          padding: EdgeInsets.only(
                            left: setWidth(13),
                            right: setWidth(30),
                            top: setHeight(20),
                            bottom: setHeight(20),
                          ),
                          child: Row(
                            children: <Widget>[
                              Text(
                                "车        主：",
                                style: TextStyle(
                                  color: Color(0xFF333333),
                                  fontSize: setFontSize(30),
                                ),
                              ),
                              InkWell(
                                child: Text(
                                  "${orderNewsModel.data.rRealname}  (${orderNewsModel.data.carNumber})",
                                  style: TextStyle(
                                    color: Color(0xFF267DFF),
                                    fontSize: setFontSize(28),
                                  ),
                                ),
                                onTap: () {
                                  print("object");
                                  uploadCarUserData();
                                },
                              ),
                              InkWell(
                                child: Text(
                                  "  ${orderNewsModel.data.mobile}",
                                  style: TextStyle(
                                    color: Color(0xFF267DFF),
                                    fontSize: setFontSize(28),
                                  ),
                                ),
                                onTap: () {
                                  print("object");
                                  launch("tel://${orderNewsModel.data.mobile}");
                                },
                              ),
                            ],
                          ),
                        ),
                      ),
                Container(
                  padding: EdgeInsets.only(
                    left: setWidth(30),
                    right: setWidth(30),
                  ),
                  child: Column(children: <Widget>[
                    addressView(
                      "发",
                      orderNewsModel.data.sRealname,
                      orderNewsModel.data.sMobile,
                      orderNewsModel.data.sAddress +
                          orderNewsModel.data.sBuildingNumber,
                    ),
                    SizedBox(height: setHeight(30)),
                    Container(
                      color: Color(0xFFE1E1E1),
                      height: 1,
                      padding: EdgeInsets.only(
                          left: setWidth(20), right: setWidth(20)),
                    ),
                    SizedBox(height: setHeight(30)),
                    addressView(
                      "收",
                      orderNewsModel.data.rRealname,
                      orderNewsModel.data.rMobile,
                      orderNewsModel.data.rAddress +
                          orderNewsModel.data.rBuildingNumber,
                    ),
                  ]),
                ),
                SizedBox(height: setHeight(30)),
                Container(
                  color: Color(0xFFE1E1E1),
                  height: 1,
                ),
                isShow ? otherView() : Container(),
                btnView()
              ],
            ),
          );
  }

  // 订单信息显示的界面
  Widget orderView() {
    return orderNewsModel == null
        ? Container()
        : Positioned(
            left: 10,
            right: 10,
            bottom: 0.0,
            child: Container(
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(6), topRight: Radius.circular(6)),
                boxShadow: [
                  BoxShadow(
                      color: Colors.black12,
                      offset: Offset(0.0, -1.0), //阴影xy轴偏移量
                      blurRadius: 15.0, //阴影模糊程度
                      spreadRadius: 1.0 //阴影扩散程度
                      )
                ],
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    padding: EdgeInsets.only(
                      left: setWidth(30),
                      right: setWidth(30),
                    ),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Text(
                          "订单详情",
                          style: TextStyle(
                            color: Color(0xFF333333),
                            fontSize: setFontSize(32),
                          ),
                        ),
                        IconButton(
                          icon: Image.asset(
                            !isShow
                                ? "images/OrderShowImage.png"
                                : "images/OrderHideImage.png",
                            width: setWidth(130),
                          ),
                          onPressed: () {
                            print("object");
                            setState(() {
                              isShow = !isShow;
                            });
                          },
                        ),
                        Text(
                          "订单详情",
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: setFontSize(32),
                          ),
                        ),
                      ],
                    ),
                  ),
                  // 判断车主信息 是否展示
                  orderType == 1 || orderType == 5
                      ? Container()
                      : Container(
                          padding: EdgeInsets.all(setWidth(18)),
                          child: Container(
                            color: Color(0xFFF2F2F2),
                            padding: EdgeInsets.only(
                              left: setWidth(13),
                              right: setWidth(30),
                              top: setHeight(20),
                              bottom: setHeight(20),
                            ),
                            child: Row(
                              children: <Widget>[
                                Text(
                                  "车        主：",
                                  style: TextStyle(
                                    color: Color(0xFF333333),
                                    fontSize: setFontSize(30),
                                  ),
                                ),
                                InkWell(
                                  child: Text(
                                    "${orderNewsModel.data.rRealname}  (${orderNewsModel.data.carNumber})",
                                    style: TextStyle(
                                      color: Color(0xFF267DFF),
                                      fontSize: setFontSize(28),
                                    ),
                                  ),
                                  onTap: () {
                                    print("object");
                                    uploadCarUserData();
                                  },
                                ),
                                InkWell(
                                  child: Text(
                                    "  ${orderNewsModel.data.mobile}",
                                    style: TextStyle(
                                      color: Color(0xFF267DFF),
                                      fontSize: setFontSize(28),
                                    ),
                                  ),
                                  onTap: () {
                                    print("object");
                                    launch(
                                        "tel://${orderNewsModel.data.mobile}");
                                  },
                                ),
                              ],
                            ),
                          ),
                        ),
                  Container(
                    padding: EdgeInsets.only(
                      left: setWidth(30),
                      right: setWidth(30),
                    ),
                    child: Column(children: <Widget>[
                      addressView(
                        "发",
                        orderNewsModel.data.sRealname,
                        orderNewsModel.data.sMobile,
                        orderNewsModel.data.sAddress +
                            orderNewsModel.data.sBuildingNumber,
                      ),
                      SizedBox(height: setHeight(30)),
                      Container(
                        color: Color(0xFFE1E1E1),
                        height: 1,
                        padding: EdgeInsets.only(
                            left: setWidth(20), right: setWidth(20)),
                      ),
                      SizedBox(height: setHeight(30)),
                      addressView(
                        "收",
                        orderNewsModel.data.rRealname,
                        orderNewsModel.data.rMobile,
                        orderNewsModel.data.rAddress +
                            orderNewsModel.data.rBuildingNumber,
                      ),
                    ]),
                  ),
                  SizedBox(height: setHeight(30)),
                  Container(
                    color: Color(0xFFE1E1E1),
                    height: 1,
                  ),
                  isShow ? otherView() : Container(),
                  btnView()
                ],
              ),
            ),
          );
  }

  Widget otherView() {
    return Column(
      children: <Widget>[
        SizedBox(height: setHeight(30)),
        Container(
          padding: EdgeInsets.only(
            left: setWidth(30),
            right: setWidth(30),
          ),
          child: Column(
            children: <Widget>[
              rowView("订单编号：", orderNewsModel.data.orderNumber),
              rowView("备        注：", orderNewsModel.data.goodsRemark),
              newsStr().length != 0 ? rowView("货物信息：", newsStr()) : Container(),
              rowView("发货时间：", orderNewsModel.data.delivergoodstime),
              endView(),
            ],
          ),
        ),
        Container(
          color: Color(0xFFE1E1E1),
          height: setHeight(20),
        ),
      ],
    );
  }

  String newsStr() {
    String shopnews = "";
    if (orderNewsModel.data.csGoodsNumber != 0) {
      shopnews = shopnews +
          orderNewsModel.data.csGoodsName +
          orderNewsModel.data.csGoodsNumber.toString();
    }
    if (orderNewsModel.data.bsGoodsNumber != 0) {
      shopnews = shopnews +
          " " +
          orderNewsModel.data.bsGoodsName +
          orderNewsModel.data.bsGoodsNumber.toString();
    }

    if (orderNewsModel.data.otherGoodsName != null) {
      shopnews = shopnews + " " + orderNewsModel.data.otherGoodsName;
    }

    return shopnews;
  }

  Widget endView() {
    switch (orderType) {
      case 1:
      case 5:
        {
          return rowView("发布时间：", orderNewsModel.data.createtimeText);
        }
        break;
      case 2:
        {
          return rowView("接单时间：", orderNewsModel.data.reciveOrderTime);
        }
        break;
      default:
        {
          return rowView("取件时间：", orderNewsModel.data.pickUpTime);
        }
    }
  }

  Widget addressView(
    String typeStr,
    String name,
    String mobile,
    String address,
  ) {
    return Row(
      children: <Widget>[
        Text(
          "$typeStr:",
          style: TextStyle(color: Color(0xFF333333), fontSize: setFontSize(30)),
        ),
        SizedBox(width: setWidth(20)),
        Expanded(
            child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Row(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: <Widget>[
                Text(
                  name,
                  style: TextStyle(
                    color: Color(0xFF333333),
                    fontSize: setFontSize(30),
                  ),
                ),
                InkWell(
                  child: Text(
                    mobile,
                    style: TextStyle(
                      color: Color(0xFF267DFF),
                      fontSize: setFontSize(30),
                    ),
                  ),
                  onTap: () {
                    print(mobile);
                    showCallDialog(context, mobile);
                  },
                )
              ],
            ),
            SizedBox(height: setHeight(10)),
            Text(
              address,
              style: TextStyle(
                  color: Color(0xFF666666), fontSize: setFontSize(24)),
            ),
          ],
        ))
      ],
    );
  }

  showCallDialog(BuildContext context, String mobile) {
    //显示对话框
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text("确定要拨打$mobile 吗?"),
          // content: Text("确定要退出吗?"),
          // 设置成 圆角
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
          actions: [
            FlatButton(
              child: Text(
                "取消",
                style: TextStyle(
                  fontSize: setFontSize(30),
                ),
              ),
              onPressed: () {
                Navigator.pop(context);
              },
            ),
            FlatButton(
              child: Text(
                "确认",
                style: TextStyle(
                  color: Colors.orange,
                  fontSize: setFontSize(30),
                ),
              ),
              onPressed: () {
                launch("tel://$mobile");
              },
            ),
          ],
        );
      },
    );
  }

  Widget rowView(String typeStr, String content) {
    return Column(
      children: <Widget>[
        Row(
          children: <Widget>[
            Text(
              typeStr,
              style: TextStyle(
                color: Color(0xFF333333),
                fontSize: setFontSize(30),
              ),
            ),
            Expanded(
              child: Text(
                content,
                style: TextStyle(
                  color: Color(0xFF333333),
                  fontSize: setFontSize(28),
                ),
              ),
            )
          ],
        ),
        SizedBox(height: setHeight(30)),
      ],
    );
  }

  Widget btnView() {
    return Container(
      padding: EdgeInsets.fromLTRB(
        setWidth(20),
        setHeight(30),
        setWidth(20),
        setHeight(30),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Expanded(
            child: Text(
              "共计:${orderNewsModel.data.orderPrice}元",
              style: TextStyle(
                color: Colors.red,
                fontSize: setFontSize(34),
              ),
            ),
          ),
          orderType == 2 || orderType == 1
              ? Row(
                  children: [
                    orderNewsModel.data.payStatus == 1 ||
                            orderNewsModel.data.payType == 3
                        ? Container()
                        : InkWell(
                            child: mainBtnView(
                              "支付订单",
                              fontWeight: FontWeight.bold,
                            ),
                            onTap: () {
                              showPayView(context);
                            },
                          ),
                    SizedBox(width: 4),
                    InkWell(
                      child: mainBtnView(
                        "取消订单",
                        fontWeight: FontWeight.bold,
                      ),
                      onTap: () {
                        DioUtils.postHttp(
                          context,
                          "index/cancel_reason",
                          parameters: {"type": "1"},
                          onSuccess: (t) {
                            print(t);
                            MainModel model = MainModel.fromJson(t);
                            if (model.code == 1 && model.data != null) {
                              if (mounted) {
                                setState(() {
                                  disOrderModel = DisOrderModel.fromJson(t);
                                  remove = 1;
                                });
                              }
                            }
                          },
                          onError: (error) {
                            print(error);
                          },
                        );
                      },
                    )
                  ],
                )
              : mainBtnView(
                  "已取件",
                  titleColor: Color(0xFF999999),
                  backColor: Color(0xFFC9C9C9),
                  lineColor: Color(0xFF999999),
                  fontWeight: FontWeight.w700,
                )
        ],
      ),
    );
  }

  void showPayView(BuildContext context) {
    showModalBottomSheet(
      context: context,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
      enableDrag: false, //设置不能拖拽关闭
      isDismissible: false, //设置不能点击消失
      isScrollControlled: true,
      builder: (BuildContext context) {
        return StatefulBuilder(
          builder: (BuildContext context, setBottomSheetState) {
            return InkWell(
              child: Container(
                height: 180,
                padding: EdgeInsets.all(10),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(15),
                      topRight: Radius.circular(15)),
                ),
                child: ListView(
                  children: <Widget>[
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text("请选择支付方式"),
                        IconButton(
                          icon: Icon(Icons.clear),
                          onPressed: () {
                            Navigator.of(context).pop();
                          },
                        ),
                      ],
                    ),
                    SizedBox(height: 20),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        InkWell(
                          child: choosePayView(
                              "images/WeiXinPayImage.png", "微信支付"),
                          onTap: () async {
                            var isInstalled = await fluwx.isWeChatInstalled;
                            if (!isInstalled) {
                              showToast("拉取信息失败，请先安装微信");
                              return;
                            }

                            Navigator.of(context).pop();
                            toPay(orderNewsModel.data.orderNumber, "2");
                          },
                        ),
                        InkWell(
                          child:
                              choosePayView("images/AliPayImage.png", "支付宝支付"),
                          onTap: () async {
                            var isInstalled = await tobias.isAliPayInstalled();
                            if (!isInstalled) {
                              showToast("未检测到支付宝应用");
                              return;
                            }
                            Navigator.of(context).pop();
                            toPay(orderNewsModel.data.orderNumber, "1");
                          },
                        ),
                        InkWell(
                          child: choosePayView(
                              "images/MainOtherPayImage.png", "货到付款"),
                          onTap: () {
                            Navigator.of(context).pop();
                            toPay(orderNewsModel.data.orderNumber, "3");
                          },
                        ),
                      ],
                    ),
                  ],
                ),
              ),
              onTap: () {
                setBottomSheetState(() {
                  FocusScope.of(context).requestFocus(FocusNode());
                });
              },
            );
          },
        );
      },
    );
  }

  Widget choosePayView(String imageStr, String title) {
    return Column(
      children: [
        Image.asset(
          imageStr,
          height: setHeight(100),
          width: setHeight(100),
        ),
        SizedBox(height: 10),
        Text(
          title,
          style: TextStyle(
            color: Color(0xFF222222),
            fontSize: setFontSize(30),
          ),
        ),
      ],
    );
  }

  void toPay(String orderID, String payType) {
    DioUtils.postHttp(
      context,
      "payment/order_pay",
      parameters: {
        "token": getData("token"),
        "out_trade_no": orderID,
        "pay_type": payType,
      },
      onSuccess: (t) {
        print(t);
        MainModel model = MainModel.fromJson(t);
        if (model.code == 1) {
          if (payType == "1" && model.data != null) {
            tobias.aliPay(t["data"].toString()).then((value) => uploadData());
          } else if (payType == "2" && model.data != null) {
            fluwx
                .payWithWeChat(
                    appId: t["data"]["appid"],
                    partnerId: t["data"]["partnerid"],
                    prepayId: t["data"]["prepayid"],
                    packageValue: t["data"]["package"],
                    nonceStr: t["data"]["noncestr"],
                    timeStamp: int.parse(t["data"]["timestamp"].toString()),
                    sign: t["data"]["sign"])
                .then((value) => uploadData());
          } else {
            uploadData();
          }
        }
      },
      onError: (error) {
        print(error);
      },
    );
  }

  Widget removeView() {
    return Positioned(
      left: 0.0,
      bottom: 0.0,
      right: 0.0,
      child: InkWell(
        onTap: () {
          removeFocus(context);
          if (otherText01.text.length > 0) {
            setState(() {
              removeStr = otherText01.text;
            });
          }
        },
        child: Container(
          padding: EdgeInsets.all(setWidth(30)),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(setWidth(20)),
              topRight: Radius.circular(setWidth(20)),
            ),
            boxShadow: [
              BoxShadow(
                  color: Colors.black12,
                  offset: Offset(0.0, -1.0), //阴影xy轴偏移量
                  blurRadius: 15.0, //阴影模糊程度
                  spreadRadius: 1.0 //阴影扩散程度
                  )
            ],
          ),
          child: Column(
            children: dismissView(),
          ),
        ),
      ),
    );
  }

  List<Widget> dismissView() {
    List<Widget> dismissarr = [];
    for (var i = 0; i < disOrderModel.data.length + 3; i++) {
      if (i == 0) {
        dismissarr.add(
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Text(
                "确认取消订单？",
                style: TextStyle(
                    color: Color(0xFF333333), fontSize: setFontSize(36)),
              ),
              InkWell(
                child: Image.asset(
                  "images/MainDismissImage.png",
                  width: setWidth(40),
                ),
                onTap: () {
                  setState(() {
                    remove = 0;
                    if (otherText01.text.length > 0) {
                      removeStr = otherText01.text;
                    }
                  });
                },
              ),
            ],
          ),
        );
        dismissarr.add(
          SizedBox(height: setHeight(30)),
        );
      } else if (i == disOrderModel.data.length + 1) {
        dismissarr.add(
          Container(
            decoration: BoxDecoration(
                border: Border.all(color: Color(0xFFC9C9C9), width: 1)),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                SizedBox(width: setWidth(30)),
                Text(
                  "其他：",
                  style:
                      TextStyle(fontSize: setFontSize(30), color: Colors.black),
                ),
                Expanded(
                  child: TextField(
                    minLines: 1,
                    maxLines: 5,
                    controller: otherText01,
                    textAlign: TextAlign.start,
                    cursorColor: Colors.grey[400], //设置光标
                    decoration: InputDecoration(
                        border: InputBorder.none,
                        hintText: "备注",
                        hintStyle: TextStyle(
                            fontSize: setFontSize(30),
                            color: Color(0xFFAEAEAE))),
                    style: TextStyle(
                        fontSize: setFontSize(30), color: Colors.black),
                    onChanged: (value) {
                      setState(() {
                        removeStr = value;
                      });
                    },
                    onTap: () {
                      setState(() {
                        removeStr = otherText01.text;
                      });
                    },
                  ),
                )
              ],
            ),
          ),
        );
        dismissarr.add(
          SizedBox(height: setHeight(30)),
        );
      } else if (i == disOrderModel.data.length + 2) {
        dismissarr.add(
          Container(
              child: Row(
            // mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Expanded(child: Text("")),
              InkWell(
                child: mainBtnView("确认取消", fontWeight: FontWeight.bold),
                onTap: () {
                  print("object");
                  if (removeStr.length == 0) {
                    showToast("请选择或填写取消原因");
                    return;
                  }
                  showAlertDialog(context);
                },
              ),
            ],
          )),
        );
      } else {
        String disStr = disOrderModel.data[i - 1].content.toString();
        dismissarr.add(
          removeChooseView(disStr, disOrderModel.data[i - 1].id),
        );
        dismissarr.add(
          SizedBox(height: setHeight(20)),
        );
      }
    }
    return dismissarr;
  }

  Widget removeChooseView(String str, int index) {
    return InkWell(
      child: Container(
        padding: EdgeInsets.all(setWidth(30)),
        decoration: BoxDecoration(
            border: Border.all(color: Color(0xFFC9C9C9), width: 1)),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Text(
              str,
              style: TextStyle(
                color: Color(0xFF333333),
                fontSize: setFontSize(28),
              ),
            ),
            Image.asset(
              removeStr == str
                  ? "images/MainSelectImage.png"
                  : "images/MainNoneImage.png",
              height: setHeight(40),
            )
          ],
        ),
      ),
      onTap: () {
        print("object");
        removeFocus(context);
        setState(() {
          removeStr = str;
        });
      },
    );
  }

  showAlertDialog(BuildContext context) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('你确定要取消该订单吗?'),
          actions: <Widget>[
            FlatButton(
              child: Text('取消'),
              onPressed: () {
                print('取消');
                Navigator.of(context).pop();
              },
            ),
            FlatButton(
              child: Text('确定'),
              onPressed: () {
                dismissOrder();
              },
            )
          ],
        );
      },
    );
  }

  void dismissOrder() {
    DioUtils.postHttp(
      context,
      "goodsuser/cancel_order",
      parameters: {
        "token": getData("token"),
        "order_id": widget.orderID,
        "concel_order_reson": removeStr
      },
      onSuccess: (t) {
        print(t);
        if (t["code"].toString() == "1") {
          Navigator.pop(context);
          Navigator.pop(context);
        }
      },
      onError: (error) {
        print(error);
      },
    );
  }

  String btnStr() {
    if (orderType == 2 || orderType == 1) {
      return "取消订单";
    } else {
      return "确认送达";
    }
  }

  void uploadCarUserData() {
    DioUtils.postHttp(
      context,
      "goodsuser/caruser_info",
      parameters: {"token": getData("token"), "order_id": widget.orderID},
      onSuccess: (t) {
        print(t);
        MainModel model = MainModel.fromJson(t);
        if (model.code == 1 && model.data != null) {
          if (mounted) {
            setState(() {
              carUserNews = CarUserNews.fromJson(t);
            });
            showCarNewsView(context);
          }
        }
      },
      onError: (error) {
        print(error);
      },
    );
  }

  void showCarNewsView(BuildContext context) {
    showModalBottomSheet(
      context: context,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
      enableDrag: false, //设置不能拖拽关闭
      isDismissible: true, //设置不能点击消失
      isScrollControlled: true,
      builder: (BuildContext context) {
        return Container(
          height: 500,
          padding: EdgeInsets.fromLTRB(
            setWidth(30),
            setWidth(10),
            setWidth(30),
            setWidth(30),
          ),
          decoration: BoxDecoration(
            color: Color(0xFFF2F2F2),
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(15), topRight: Radius.circular(15)),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text(""),
                  IconButton(
                    icon: Icon(Icons.clear),
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                  ),
                ],
              ),
              Row(
                children: <Widget>[
                  ClipOval(
                    child: CachedNetworkImage(
                      imageUrl: carUserNews.data.info.avatar,
                      height: setHeight(110),
                      width: setHeight(110),
                      fit: BoxFit.cover,
                    ),
                  ),
                  SizedBox(width: setWidth(20)),
                  Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Text(
                          "${carUserNews.data.info.realname}  (${carUserNews.data.info.carNumber})",
                          style: TextStyle(
                            color: Color(0xFF333333),
                            fontSize: setFontSize(30),
                            fontWeight: FontWeight.w700,
                          ),
                        ),
                        Text(
                          " ${carUserNews.data.info.mobile}",
                          style: TextStyle(
                            color: Color(0xFF333333),
                            fontSize: setFontSize(30),
                            fontWeight: FontWeight.w700,
                          ),
                        )
                      ]),
                ],
              ),
              SizedBox(height: 10),
              Text(
                "他的评价：${carUserNews.data.commentLevel}",
                style: TextStyle(
                  color: Color(0xFF333333),
                  fontSize: setFontSize(30),
                  fontWeight: FontWeight.w700,
                ),
              ),
              SizedBox(height: 10),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  showChooseView("好评：${carUserNews.data.goodComment}"),
                  showChooseView("一般：${carUserNews.data.generalComment}"),
                  showChooseView("差评：${carUserNews.data.badComment}"),
                ],
              ),
              SizedBox(height: 10),
              Text(
                "其他",
                style: TextStyle(
                  color: Color(0xFF666666),
                  fontSize: setFontSize(30),
                ),
              ),
              SizedBox(height: 10),
              Text(
                carUserNews.data.info.content == null
                    ? "暂无评论"
                    : carUserNews.data.info.content,
                style: TextStyle(
                  color: Color(0xFF666666),
                  fontSize: setFontSize(30),
                ),
              ),
              SizedBox(height: 10),
              Text(
                "车辆照片",
                style: TextStyle(
                  color: Color(0xFF333333),
                  fontSize: setFontSize(30),
                  fontWeight: FontWeight.w700,
                ),
              ),
              SizedBox(height: 10),
              Expanded(
                child: CachedNetworkImage(
                  imageUrl: carUserNews.data.info.carImage,
                  fit: BoxFit.contain,
                ),
              )
            ],
          ),
        );
      },
    ).then((val) {
      print(val);
    });
  }

  Widget showChooseView(String string) {
    return Container(
      padding: EdgeInsets.fromLTRB(
        setWidth(40),
        setHeight(10),
        setWidth(40),
        setHeight(10),
      ),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.all(Radius.circular(2)),
          border: Border.all(color: Color(0xFFFF8629), width: 1)),
      child: Text(
        string,
        style: TextStyle(
          color: Color(0xFFFF8629),
          fontSize: setFontSize(30),
        ),
      ),
    );
  }
}

class CarUserNews {
  int code;
  String msg;
  String time;
  Data data;

  CarUserNews({this.code, this.msg, this.time, this.data});

  CarUserNews.fromJson(Map<String, dynamic> json) {
    code = json['code'];
    msg = json['msg'];
    time = json['time'];
    data = json['data'] != null ? new Data.fromJson(json['data']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['code'] = this.code;
    data['msg'] = this.msg;
    data['time'] = this.time;
    if (this.data != null) {
      data['data'] = this.data.toJson();
    }
    return data;
  }
}

class Data {
  Info info;
  int goodComment;
  int generalComment;
  int badComment;
  String commentLevel;

  Data(
      {this.info,
      this.goodComment,
      this.generalComment,
      this.badComment,
      this.commentLevel});

  Data.fromJson(Map<String, dynamic> json) {
    info = json['info'] != null ? new Info.fromJson(json['info']) : null;
    goodComment = json['good_comment'];
    generalComment = json['general_comment'];
    badComment = json['bad_comment'];
    commentLevel = json['comment_level'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.info != null) {
      data['info'] = this.info.toJson();
    }
    data['good_comment'] = this.goodComment;
    data['general_comment'] = this.generalComment;
    data['bad_comment'] = this.badComment;
    data['comment_level'] = this.commentLevel;
    return data;
  }
}

class Info {
  int id;
  String content;
  int carUserId;
  String avatar;
  String mobile;
  String realname;
  String carNumber;
  String carImage;

  Info(
      {this.id,
      this.content,
      this.carUserId,
      this.avatar,
      this.mobile,
      this.realname,
      this.carNumber,
      this.carImage});

  Info.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    content = json['content'];
    carUserId = json['car_user_id'];
    avatar = json['avatar'];
    mobile = json['mobile'];
    realname = json['realname'];
    carNumber = json['car_number'];
    carImage = json['car_image'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['content'] = this.content;
    data['car_user_id'] = this.carUserId;
    data['avatar'] = this.avatar;
    data['mobile'] = this.mobile;
    data['realname'] = this.realname;
    data['car_number'] = this.carNumber;
    data['car_image'] = this.carImage;
    return data;
  }
}
